import re # 正则表达式 *** !!!

#match 开始
pattern = '\d\.\d+'
s1='I study Python 3.11 everyday'
s2='I study Python everyday'
s3='I study Python 3.11 everyday 2.7'
match=re.match(pattern,s1,re.I) #忽略大小写
print(match)
s12='3.11 I study Python everyday'
match2=re.match(pattern,s12,re.I)
print(match2)

print('匹配值的起始位置:',match2.start())
print('匹配值的结束位置:',match2.end())
print('匹配区间的位置元素:',match2.span()) #元组
print('待匹配的字符串:',match2.string)
print('匹配的数据:',match2.group())

print('='*50)
#search 任何位置
search = re.search(pattern,s1)
print(search)
print(search.group())
search2 = re.search(pattern,s2)
print(search2)

search3 = re.search(pattern,s3)
print(search3)

print('='*50)
#findall 所有匹配

lst1=re.findall(pattern,s1)
lst2=re.findall(pattern,s2)
lst3=re.findall(pattern,s3)

print(lst1)
print(lst2)
print(lst3)

print('='*50)
#替换和分割

pattern='黑客|破解|反爬'
s='我想学习Python，想破解一些VIP视频，Python可以实现无底线反爬吗？'
new_s=re.sub(pattern,'XXX',s)
print(new_s)

s='https://www.baidu.com/s?wd=ysj&rsv_spt=1'
pattern2='[?|&]'
lst=re.split(pattern2,s)
print(lst)



